<?php

if (isset($_POST["mes"]) && isset($_POST["ano"])) {
    $mes = $_POST["mes"];
    $ano = $_POST["ano"];
} else {
    $mes = date('m');
    $ano = date('Y');
}

if (!isset($data[2])) {
    $data[2] = "";
}

// botão para imprimir
if ($this->controllerACL->permissaoBotao("relatorio/imprimir") && $data[2] == "imprimir") {
    echo "<input type='button' id='print' value='Imprimir' class='mws-button green right select-grid margin-10px'/>";
}
?>

<div id="imprimir-hide" class="mws-panel grid_8">
    <div class="mws-panel-header">
        <span class="mws-i-24 i-table-1">Relatórios</span>
        <form action="<?php echo BASE_URL; ?>relatorio/imprimir" method="POST" target="_blank">
            <select id="ano" class="input-small right select-grid" name="ano">
                <?php
                foreach ($data[1] as $anoL) {
                    echo "<option value='" . $anoL . "'";

                    if ($anoL == $ano) {
                        echo " SELECTED";
                    }

                    echo ">" . $anoL . "</option>";
                }
                ?>
            </select>   
            <select id="mes" class="input-small right select-grid" name="mes">
                <?php
                foreach ($data[0] as $mesL) {
                    echo "<option value='" . $mesL->codigo . "'";

                    if ($mesL->codigo == $mes) {
                        echo " SELECTED";
                    }

                    echo ">" . $mesL->mes . "</option>";
                }
                ?>
            </select>
            <?php
            // botão para imprimir
            if ($this->controllerACL->permissaoBotao("relatorio/imprimir")) {
                echo "<input type='submit' id='imprimir' value='Imprimir' class='mws-button green right select-grid btn-header'/>";
            }
            ?>
        </form>
    </div>
</div>
<div class="mws-panel grid_8">
    <div id="relatorio">
    </div>
</div>

<script type="text/javascript">
    $("#relatorio").load("<?php echo BASE_URL; ?>relatorio/lista", {mes: $('#mes').val(), ano: $('#ano').val()});

    $(".select-grid").on("change", function() {
        loadEntradasMes();
    });

    $("#print").on("click", function() {
        $(this).hide();
        window.print();
    });

    function loadEntradasMes() {
        $("#relatorio").load("<?php echo BASE_URL; ?>relatorio/lista", {mes: $('#mes').val(), ano: $('#ano').val()});
    }

    if ("<?php echo $data[2]; ?>" == "imprimir") {
        $('#mws-header, #mws-sidebar-stitch, #mws-sidebar-bg, #mws-sidebar, #imprimir-hide, #mws-footer').hide();
        $('#mws-wrapper').addClass('relatorio-print');
    }


</script>